<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<body>
<div class="x-body layui-anim layui-anim-up">
    <fieldset class="layui-elem-field">
        <legend>数据统计</legend>
        <div class="layui-field-box">
            <div class="layui-col-md12">
                <div class="layui-card">
                    <div class="layui-card-body">
                        <div class="layui-carousel x-admin-carousel x-admin-backlog" lay-anim="" lay-indicator="inside"
                             lay-arrow="none" style="width: 100%; height: 90px;">
                            <div carousel-item="">
                                <ul class="layui-row layui-col-space10 layui-this">
                                    <li class="layui-col-xs2">
                                        <a href="javascript:;" class="x-admin-backlog-body">
                                            <h3>用户数量</h3>
                                            <p><cite id="userNumId"></cite></p>
                                        </a>
                                    </li>
                                    <li class="layui-col-xs2">
                                        <a href="javascript:;" class="x-admin-backlog-body">
                                            <h3>物品种类数量</h3>
                                            <p><cite id="kindsNumId"></cite></p>
                                        </a>
                                    </li>
                                    <li class="layui-col-xs2">
                                        <a href="javascript:;" class="x-admin-backlog-body">
                                            <h3>物品总数量</h3>
                                            <p><cite id="goodsNumId"></cite></p>
                                        </a>
                                    </li>
                                    <li class="layui-col-xs2">
                                        <a href="javascript:;" class="x-admin-backlog-body">
                                            <h3>物品在库数量</h3>
                                            <p><cite id="storeGoodsNumId"></cite></p>
                                        </a>
                                    </li>
                                    <li class="layui-col-xs2">
                                        <a href="javascript:;" class="x-admin-backlog-body">
                                            <h3>角色数量</h3>
                                            <p><cite id="roleNumId"></cite></p>
                                        </a>
                                    </li>
                                    <li class="layui-col-xs2">
                                        <a href="javascript:;" class="x-admin-backlog-body">
                                            <h3>借阅数量</h3>
                                            <p><cite id="borrowNumId"></cite></p>
                                        </a>
                                    </li>
                                </ul>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </fieldset>
    <fieldset class="layui-elem-field">
        <legend>最新借阅通知</legend>
        <ul class="layui-timeline" id="timeLineId">

        </ul>
    </fieldset>
    <fieldset class="layui-elem-field">
        <legend>开发团队</legend>
        <div class="layui-field-box">
            <table class="layui-table">
                <tbody>
                <tr>
                    <th>版权所有</th>
                    <td>竹类病虫防控与资源开发四川省重点实验室
                        <a href="http://119.3.141.104:8080" class='x-a' target="_blank">访问后台系统</a></td>
                    <td></td>
                </tr>
                <tr>
                    <th>开发者</th>
                    <td>杜健华(251523891@qq.com)</td>
                    <td>杜志华(251523891@qq.com)</td>
                </tr>
                </tbody>
            </table>
        </div>
    </fieldset>
</div>

<script>
    $.ajax({
        url: "/user/getUserNum",
        success: function (result) {
            if (0 == result.code) {
                var userNumObj = $("#userNumId");
                userNumObj[0].innerText = result.data;
            }
        }
    })
    $.ajax({
        url: "/kinds/getKindsNum",
        success: function (result) {
            if (0 == result.code) {
                var kindsNumObj = $("#kindsNumId");
                kindsNumObj[0].innerText = result.data;
            }
        }
    })
    $.ajax({
        url: "/goods/getGoodsNum",
        success: function (result) {
            if (0 == result.code) {
                var goodsNumObj = $("#goodsNumId");
                goodsNumObj[0].innerText = result.data;
            }
        }
    })
    $.ajax({
        url: "/goods/getStoreGoodsNum",
        success: function (result) {
            if (0 == result.code) {
                var StoreGoodsNumObj = $("#storeGoodsNumId");
                StoreGoodsNumObj[0].innerText = result.data;
            }
        }
    })
    $.ajax({
        url: "/role/getRoleNum",
        success: function (result) {
            if (0 == result.code) {
                var roleNumObj = $("#roleNumId");
                roleNumObj[0].innerText = result.data;
            }
        }
    })
    $.ajax({
        url: "/borrow/getBorrowNum",
        success: function (result) {
            if (0 == result.code) {
                var borrowNumObj = $("#borrowNumId");
                borrowNumObj[0].innerText = result.data;
            }
        }
    })
    $.ajax({
        url: "/log/getRecentlyBorrowLog",
        success: function (result) {
            if (result.code === 0) {

            }
        }
    })

    $.ajax({
        url: "/borrow/getRecentlyBorrowInfo",
        success: function (result) {
            if (result.code === 0) {
                debugger;
                var str = "";
                var handle = "";
                var start = 0;
                var person = "";
                var time = "";
                if(result.count>=5){
                    start = result.count-5;
                }
                for (var i = start; i < result.count; i++) {
                    if(result.data[i].borrowHandleState==="无需归还"){
                        time = dateToStr(result.data[i].borrowTime);
                        handle = "借阅了";
                        person = result.data[i].borrowPerson;
                    }else if(result.data[i].borrowHandleState==="已同意归还申请"){
                        time = dateToStr(result.data[i].returnTime);
                        handle = "已同意"+result.data[i].borrowPerson+"归还";
                        person = result.data[i].modifyPerson;
                    }else if(result.data[i].borrowHandleState==="已同意借阅申请"){
                        time = dateToStr(result.data[i].borrowTime);
                        handle = "已同意"+result.data[i].borrowPerson+"借阅";
                        person = result.data[i].modifyPerson;
                    }else if(result.data[i].borrowHandleState==="正在进行借阅申请"){
                        time = dateToStr(result.data[i].borrowTime);
                        handle = result.data[i].borrowHandleState;
                        person = result.data[i].borrowPerson;
                    }else if(result.data[i].borrowHandleState==="正在进行归还申请"){
                        time = dateToStr(result.data[i].returnTime);
                        handle = result.data[i].borrowHandleState;
                        person = result.data[i].borrowPerson;
                    }
                    str =
                        '<i class="layui-icon layui-timeline-axis" style="color: black">&#xe6af</i>' +
                        '<div class="layui-timeline-content layui-text">' +
                        '<h3 class="layui-timeline-title">' + time + '</h3>' +
                        '<p>'+
                         person+handle+result.data[i].borrowNum+"个"+result.data[i].borrowGoods+
                        '</p>'+
                        '</div>';

                    var li = document.createElement('li');
                    li.className = "layui-timeline-item"
                    li.innerHTML = str;
                    document.getElementById('timeLineId').appendChild(li);
                }
            }
        }
    })
    function dateToStr(date) {
        if (null == date || "" === date) {
            return "";
        }
        var time = new Date(date);
        var y = time.getFullYear();
        var M = time.getMonth() + 1;
        M = M < 10 ? ("0" + M) : M;
        var d = time.getDate();
        d = d < 10 ? ("0" + d) : d;
        var h = time.getHours();
        h = h < 10 ? ("0" + h) : h;
        var m = time.getMinutes();
        m = m < 10 ? ("0" + m) : m;
        var s = time.getSeconds();
        s = s < 10 ? ("0" + s) : s;
        var str = y + "-" + M + "-" + d + " " + h + ":" + m + ":" + s;
        return str;
    }
</script>
</body>
